package com.doraemon.mapper;

import com.doraemon.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 购物车管理Mapper
 **/
@Mapper
public interface ShoppingCartMapper {

    /***
     * 根据 购物车实体 条件查询
     * ---
     * @param shoppingCart 购物车实体
     * @return: java.util.List<com.doraemon.entity.ShoppingCart>
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /***
     * 根据 购物车实体 更新数量
     * ---
     * @param shoppingCart 购物车实体
     * @return: void
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    /***
     * 根据 购物车实体 插入数据
     * ---
     * @param shoppingCart 购物车实体
     * @return: void
     */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) " + " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /***
     * 根据 用户id 清空购物车
     * ---
     * @param userId 用户id
     * @return: void
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void cleanByUserId(Long userId);

    /***
     * 根据 购物车实体 删除指定商品
     * ---
     * @param shoppingCart
     * @return: void
     */
    void delete(ShoppingCart shoppingCart);
}
